package com.jun.seckill_by_jun.dao;

import com.jun.seckill_by_jun.domain.Goods;
import com.jun.seckill_by_jun.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsDao {
    @Select("SELECT g.*,gs.seckill_price,gs.stock_count,gs.start_date,gs.end_date,gs.version FROM sk_goods_seckill gs LEFT JOIN sk_goods g ON gs.goods_id = g.id")
    public List<GoodsVo> listGoodsVo();

    @Select("SELECT g.*,gs.seckill_price,gs.stock_count,gs.start_date,gs.end_date,gs.version FROM sk_goods_seckill gs LEFT JOIN sk_goods g ON gs.goods_id = g.id where g.id = #{goodsId}")
    public GoodsVo getGoodsByGoodsId(@Param("goodsId") long goodsId);

    @Update("update sk_goods_seckill set stock_count = stock_count - 1 where goods_id = #{id} and stock_count>0")
    public boolean reduceStock(Goods goods);
}
